package spring.cloud.tasks.executor.listener;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;

/**
 * 作业注册中心的监听器.
 */
@Slf4j
@Setter
@Getter
public abstract class TreeCacheListener implements org.apache.curator.framework.recipes.cache.TreeCacheListener {

    @Override
    public final void childEvent(final CuratorFramework curatorFramework, final TreeCacheEvent treeCacheEvent) throws Exception {
        String path = null == treeCacheEvent.getData() ? "" : treeCacheEvent.getData().getPath();
        if (path.isEmpty()) {
            return;
        }
        dataChanged(curatorFramework, path, treeCacheEvent);
    }

    protected abstract void dataChanged(final CuratorFramework curatorFramework, final String path, final TreeCacheEvent treeCacheEvent);
}
